<template>
    <div id='' class='params_content'>
        <i-table ref="myTable" :search="getSearch" :table="getTbale" :pageConfig="pageConfig" @onSelectAll="onSelect" @onSelectOnchange="onSelect" @resetTable="ResetTable" />
        <Modal v-model="modalShow" width="1200" :mask-closable="false" :title="modalTitle">
            <components v-if="modalShow" :is="comps" ref="coms" />
            <div slot="footer">
                <Button type="text" @click="cancel">取消</Button>
                <Button type="primary" @click="ok">确定</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
import { config } from './parameter/table_config'
import addUpdata from "./parameter/add-updata.vue";
export default {
    name: '',
    props: [''],
    data() {
        return {
            search: {}, // 查询配置对象
            tableConfig: {}, // 表格配置对象
            pageConfig: config.page, // 翻页器配置
            comps: addUpdata,
            modalShow: false,
            modalTitle: '',
            removeList: [],
        };
    },
    components: {},
    computed: {
        getSearch() {
            this.search = icu.util.deepClone(config.search);// 为不改变原始配置数据，进行深度克隆。
            return this.search;
        },
        getTbale() {
            this.tableConfig = icu.util.deepClone(config.table); // 深度克隆表格配置。
            this.tableConfig.event = {
                edit: this.edit,
                add: this.add,
                remove: this.remove,
                removeLot: this.removeLot
            }
            return this.tableConfig;
        }
    },
    beforeMount() { },
    mounted() { },
    methods: {
        add(row) {
            this.modalShow = true
            this.modalTitle = '新增'
        },
        edit(event, row) {
            this.modalShow = true
            this.modalTitle = '编辑'
            this.$nextTick(() => {
                this.$refs.coms.setData(row)
            })
        },
        ok() {
            this.$refs.coms.getForm((formRes) => {
                this.modalShow = false
                this.modalTitle = ''
                this.ResetTable()
            })
        },
        cancel() {
            this.modalShow = false
            this.modalTitle = ''
        },
        remove(event, row) {
            this.$Modal.confirm({
                title: '删除确认',
                content: '确认删除该条数据？',
                onOk: () => {
                    this.$http.$post('DeleteParameterManage', { data: [row.id] }).then(res => {
                        if (res.code == 200) {
                            this.$Message.success('删除成功');
                            this.removeList = []
                            this.ResetTable()
                            return
                        }
                        this.$Message.error(res.msg);
                    })
                },
            });
        },
        removeLot() {
            if (this.removeList.length === 0) {
                this.$Message.error('请选择要删除的数据！');
                return
            }
            this.$Modal.confirm({
                title: '批量删除确认',
                content: '确认删除选中数据？',
                onOk: () => {
                    this.$http.$post('DeleteParameterManage', { data: this.removeList }).then(res => {
                        if (res.code == 200) {
                            this.$Message.success('删除成功');
                            this.ResetTable()
                            this.removeList = []
                            return
                        }
                        this.$Message.error(res.msg);
                    })
                }
            });
        },
        ResetTable() {
            this.$refs.myTable.seach()
        },
        onSelect(selection) {
            let ids = selection.map(item => item.id)
            this.removeList = ids
        }
    },
    watch: {}
}
</script>
<style lang='less' scoped>
.params_content {
    background-color: #fff;
    padding: 0 20px;
    width: 100%;
    height: 800px;
    .table_content {
        height: 752px;
        overflow: auto;
    }
}
</style>